
#include "SourceFormat.h"

SourceFormat::SourceFormat()
{

}
SourceFormat::~SourceFormat()
{

}

const BFont* SourceFormat::font(int pos) const
{
	auto cit = itemMap.lessEqual(pos);
	if (Item* item = cit.value())
	{
		if (pos < item->range.max())
			return item->font;
	}
	return 0;
}
const BColor* SourceFormat::color(int pos) const
{
	auto cit = itemMap.lessEqual(pos);
	if (Item* item = cit.value())
	{
		if (pos < item->range.max())
			return &item->color;
	}
	return 0;
}

SourceFormat::Item* SourceFormat::insert(BExp* exp)
{
	Item* item = new Item(exp);
	itemMap.insert(item->range.min(), item);
	switch (exp->syntax)
	{
	case Syntax_None:
	{
		item->color.set(123, 100, 86);
		break;
	}
	case Syntax_Note:
	{
		item->color.set(64, 128, 64);
		break;
	}
	case Syntax_Include:
	{
		item->color.set(123, 100, 86);
		break;
	}
	case Syntax_File:
	{
		item->color.set(128, 10, 10);
		break;
	}
	case Syntax_Type:
	{
		item->color.set(32, 64, 200);
		break;
	}
	case Syntax_Value:
	{
		if (exp->type == "string")
			item->color.set(128, 10, 10);
		else
			item->color.set(123, 86, 123);
		break;
	}
	case Syntax_Name:
	{
		item->color.set(10, 30, 60);
		break;
	}
	case Syntax_Self:
	{
		item->color.set(128, 32, 128);
		break;
	}
	case Syntax_Opera:
	{
		break;
	}
	case Syntax_Call:
	{
		item->color.set(128, 128, 32);
		break;
	}
	case Syntax_Method:
	case Syntax_Function:
	{
		item->color.set(86, 156, 86);
		break;
	}
	case Syntax_If:
	case Syntax_Else:
	case Syntax_For:
	case Syntax_While:
	case Syntax_Switch:
	case Syntax_Case:
	case Syntax_Default:
	case Syntax_Continue:
	case Syntax_Break:
	case Syntax_Return:
	{
		item->color.set(128, 32, 128);
		item->exp = 0;
		break;
	}
	case Syntax_Const:
	case Syntax_Virtual:
	case Syntax_Class:
	case Syntax_Public:
	case Syntax_Protected:
	case Syntax_Private:
	{
		item->color.set(123, 86, 200);
		break;
	}
	default:
		break;
	}
	return item;
}
void SourceFormat::clear()
{
	itemMap.clear();
}
